#!/bin/sh
#
# construct_isa_ssh.sh
#
# Copyright (C) 2013 NTT Software Corporation.

username=$1

if [ ! -e "/home/$username/.ssh/id_rsa.pub" ];then
	su $username -c "rm -fr ~/.ssh; mkdir ~/.ssh; ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ''; chmod 700 ~/.ssh; chmod 600 ~/.ssh/*"

	if [ $? -ne 0 ]; then
		exit 100
	fi

	id_rsa_pub=`su $username -c "cat ~/.ssh/id_rsa.pub"`

	if [ $? -ne 0 ]; then
		exit 100
	fi

	exit 0
fi
